#include "stdafx.h"
#include "ToolBar24BitImage.h"

BEGIN_MESSAGE_MAP(C24BitImageToolBar, CToolBar)
	//{{AFX_MSG_MAP(myStatusBar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL C24BitImageToolBar::Load24BitToolBar( UINT nIDResource , UINT nIDDisabledImage )
{
	if ( LoadToolBar( nIDResource ) &&
	Load24bitToolbarIcons( TB_SETIMAGELIST, nIDResource ) &&
	Load24bitToolbarIcons( TB_SETDISABLEDIMAGELIST, nIDDisabledImage ) )
		return true;
	else return false;
}

BOOL C24BitImageToolBar::Load24bitToolbarIcons( int TypeOfToolBarImage, int ImageID )
{
	CImageList	ImageList;
	CBitmap		Bitmap;
	BITMAP		BitmapInfo;

	if ( Bitmap.Attach(LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE( ImageID ),
								  IMAGE_BITMAP, 0, 0,
								  LR_DEFAULTSIZE|LR_CREATEDIBSECTION)) )
	{
	    Bitmap.GetBitmap( &BitmapInfo );
		ImageList.Create( 23, BitmapInfo.bmHeight, ILC_COLOR24|ILC_MASK, BitmapInfo.bmWidth/23, 0 );
		if ( ImageList.Add(&Bitmap, RGB(255, 255, 255)) == -1 )
			return false;
		this->SendMessage(TypeOfToolBarImage, 0, (LPARAM)ImageList.m_hImageList);
		ImageList.Detach(); 
		return true;
	}
	return false;
}

BOOL C24BitImageToolBar::SetButtonsStyle( CArray<UINT> &IDs, UINT NewStyle )
{
	int index = 0;
	UINT ChangedButtonsCount = 0;
	while (( index < this->GetCount() ) && ( ChangedButtonsCount < IDs.GetCount() ))
	{
		UINT ItemId = this->GetItemID(index);
		for ( int CompareCounter = 0; CompareCounter < IDs.GetCount(); CompareCounter++ ) 
			if ( IDs[CompareCounter] == ItemId )
			{
				this->SetButtonStyle( index, NewStyle );
				ChangedButtonsCount++;
			}
		index++;
	}
	return ( ChangedButtonsCount != 0 );
}